require(['../config'], () => {
    require(['header'], () => {
        class login {
            constructor() {
                this.yzLogin()
                this.loginMsg()
            }

            yzLogin() {
                var name = document.querySelector('#name');
                var pwd = document.querySelector('#pwd');
                var btn = document.querySelector('#btn');
                name.onblur = function(str) {
                        var reg = /^[a-z](\w|\-){5,19}$/i
                        var str = name.value;
                        if (reg.test(str)) {} else {
                            alert('您输入的有误,请重新输入');
                            name.value = "";
                        }

                    }
                    //判断密码
                pwd.onblur = function() {
                    var str1 = pwd.value;
                    if (str1.length <= 6) {
                        alert('您输入的密码长度不够6位，请重新输入');
                    }
                    var reg1 = /^\d|\s|\w$/;
                    var res1 = reg1.test(str1);
                }
            }

            loginMsg() {
                $('#login-btn').on('click', function() {
                    let users = localStorage.getItem('users')
                    if (users) {
                        users = JSON.parse(users)
                        const isExist = users.some(user => {

                        })
                        if (isExist) {
                            alert('登录成功，即将跳转首页')
                                // TODO: 7天免登陆
                            utils.setCookie('loginUser', JSON.stringify({
                                username,
                                password
                            }), { path: '/' })
                            window.location.replace('/index.html')
                        } else {
                            alert('用户名或者密码错误')
                        }
                    } else {
                        alert('请先注册')
                        window.location.href = '/html/register.html'
                    }

                })
            }
        }
        new login()
    })
})